package sync.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Utils {
	
	public static String filterData(String b){
		String nums = "1234567890";
		for(int f = 0; f < b.length(); f++){
			String x = b.charAt(f)+"";
			nums = nums.replace(x, "");
		}
		return nums;
	}
	
	public static String getRandomNumber(int count){
		int arr[] = {1,2,3,4,5,6,7,8,9,0};//定义一个数组
        int len = arr.length;//获取数组长度给变量len
        String number = "";
        for(int i=0; i < count; i++){
        	 Random random = new Random();//创建随机对象
             int arrIdx = random.nextInt(len-1);
             number = number + (arr[arrIdx]+"");
        }
		return number;
	}
	
	public static int getRandomOne(){
		return Math.abs(new Random().nextInt()%10);
	}
	
	public static String filterData(String a,String b){
		// b把a里的数据过滤掉
		for(int f = 0; f < a.length(); f++){
			String x = a.charAt(f)+"";
			b = b.replace(x, "");
		}
		return b;
	}
	
	public static int[] formatStringToIntArray(String a){
		int[] b = new int[a.length()];
		for(int i = 0; i < a.length(); i++){
			b[i] = Integer.parseInt(String.valueOf(a.charAt(i)));;
		}
		return b;
	}
	
	public static String formatIntArrayToString(int[] a){
		String b = "";
		for(int i = 0; i < a.length; i++){
			b = b+a[i];
		}
		return b;
	}
	
	//方法1  
    public static String replaceRepeat(String str){  
        StringBuffer result = new StringBuffer();  
        List list = new ArrayList();  
        char[] cs = str.toCharArray();  
        for(int i=0; i<cs.length; i++){  
            if(!list.contains(cs[i])){  
                result.append(cs[i]);  
                list.add(cs[i]);  
            }  
        }  
        return result.toString();  
    }  
	
	public static int[] getRandomFromArray(int[] array, int count) {  
	    int[] a = array;  
	    int[] result = new int[count];  
	    boolean r[] = new boolean[array.length];  
	    Random random = new Random();  
	    int m = count; // 要随机取的元素个数  
	    if (m > a.length || m < 0)  
	        return a;  
	    int n = 0;  
	    while (true) {  
	        int temp = random.nextInt(a.length);  
	        if (!r[temp]) {  
	            if (n == m) // 取到足量随机数后退出循环  
	                break;  
	            n++;  
	            result[n - 1] = a[temp];  
	            r[temp] = true;  
	        }  
	    }  
	    return result;  
	}  

}
